package cn.iocoder.yudao.module.reading.controller.app.common.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页结果
 *
 * @author 芋道源码
 */
@Schema(description = "分页结果")
@Data
public final class PageResult<T> {

    @Schema(description = "数据", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<T> list;

    @Schema(description = "总量", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long total;

    @Schema(description = "当前页码", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer page;

    @Schema(description = "每页条数", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer limit;

    public PageResult() {
    }

    public PageResult(List<T> list, Long total) {
        this.list = list;
        this.total = total;
    }

    public PageResult(List<T> list, Long total, Integer page, Integer limit) {
        this.list = list;
        this.total = total;
        this.page = page;
        this.limit = limit;
    }

    public static <T> PageResult<T> empty() {
        return new PageResult<>(new ArrayList<>(), 0L);
    }

    public static <T> PageResult<T> empty(Integer page, Integer limit) {
        return new PageResult<>(new ArrayList<>(), 0L, page, limit);
    }

}
